package com.igoal.dao;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.igoal.entity.DataStatus;
import com.igoal.entity.Job;
import com.igoal.utils.StringUtils;

@Repository("jobDAO")
public class JobDAOImpl extends GenericDaoHibernate<Job, Long> implements JobDAO {

	public JobDAOImpl() {
		super(Job.class);
	}

	public Job getJobByName(String name) {
		if (StringUtils.isBlank(name)) {
			return null;
		}

		DetachedCriteria dc = DetachedCriteria.forClass(Job.class);
		dc.add(Restrictions.ilike("job_name", name, MatchMode.EXACT));
		getByStatus(dc, DataStatus.USING);
		List<Job> jobs = findByCriteria(dc);
		if (jobs.size() > 0) {
			return jobs.get(0);
		}

		return null;
	}

}
